﻿using System.Collections.Generic;
using T4UtilityBelt.UxDesigns.Controls.Renderers;

using T4UtilityBelt.Writers;

namespace T4UtilityBelt.UxDesigns.Controls
{
    public class GridRow : ContentElement<GridRow, IGridRowRenderer>
    {
        public GridRow()
        {
        }

        public GridLength Height { get; set; }

        public double? MaxHeight { get; set; }

        public double? MinHeight { get; set; }

        public int? GridRowNr { get; set; }

        private ControlCollection _controls;
        public ControlCollection Controls
        {
            get { return _controls ?? (_controls = new ControlCollection()); }
            //set { _controls = value; }
        }

        public bool HasControls
        {
            get
            {
                return _controls != null;
            }
        }

        public virtual IEnumerable<Control> AllControls()
        {
            if (HasControls)
            {
                foreach (var c in Controls)
                {
                    yield return c;
                    foreach (Control cc in c.AllControls())
                    {
                        yield return cc;
                    }
                }
            }
        }

        public override void FixModel(DataDesigns.Entity entity)
        {
            if (HasControls)
            {
                foreach (Control control in Controls)
                {
                    control.FixModel(entity);
                }
            }
        }

        public void RenderGridRowDefinition(CodeWriter writer)
        {
            this.CreateControlRenderer(writer.Platform).RenderGridRowDefinition(this, writer);
        }
    }
}